<template>
  <div class="app-container">
    <el-card style="border-radius: 10px">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
        <el-form-item label="销售订单编号" prop="soNumber">
          <el-input
            v-model="queryParams.soNumber"
            placeholder="请输入销售订单编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="销售订单名称" prop="soName">
          <el-input
            v-model="queryParams.soName"
            placeholder="请输入销售订单名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="客户名称" prop="clientName">
          <el-input
            v-model="queryParams.clientName"
            placeholder="请输入客户名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="订单日期" prop="orderDate">
          <el-date-picker clearable
                          v-model="queryParams.orderDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择订单日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">
      <el-row :gutter="10" class="mb8">

        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="orderList" border >
        <el-table-column label="销售订单编号" align="center" prop="soNumber" width="200px">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="handleView(scope.row)"
              v-hasPermi="['mes/xs:order:query']"
            >{{scope.row.soNumber}}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="销售订单名称" align="center" prop="soName" />
        <el-table-column label="客户编码" align="center" prop="clientCode" />
        <el-table-column label="客户名称" align="center" prop="clientName" />
        <el-table-column label="总金额(元)" align="center" prop="totalAmount">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.totalAmount">{{ formatCurrency(scope.row.totalAmount) }}</el-tag>
            <span v-else>{{ scope.row.totalAmount }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单日期" align="center" prop="orderDate">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="预计交货日期" align="center" prop="deliveryDate">
          <template slot-scope="scope">
            <el-tag type="warning">{{ parseTime(scope.row.deliveryDate, '{y}-{m}-{d}') }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="销售人员" align="center" prop="salesPerson" />

        <el-table-column label="操作" align="center" width="200">
          <template slot-scope="scope">
            <el-tooltip content="审批" placement="top">
              <el-button
                size="mini"
                type="primary"
                icon="el-icon-document-checked"
                @click="handleGoApprove(scope.row)"
                v-hasPermi="['mes/xs:order:approve']"
              ></el-button>
            </el-tooltip>

          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <ApproveView ref="infoView" :approve-flag="approveFlag"></ApproveView>
  </div>
</template>

<script>
import {getOrder, listApproveOrder} from "@/api/mes/xs/order";
import ApproveView from "@/views/mes/xs/order/approveView.vue";


export default {
  name: "Plan",
  components: {
    ApproveView
  },
  dicts: ['erp_payment_type'],
  data() {
    return {
      approveFlag:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购计划表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        planName: null, planDate: null, materialDeadline: null, approvalStatus: null,
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    formatCurrency(number) {
      return new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY' }).format(number);
    },
    /** 查询采购计划列表 */
    getList() {
      this.loading = true;
      listApproveOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 查询明细按钮操作
    handleView(row){
      this.$refs.infoView.open = true;
      this.approveFlag=false;
      this.$refs.infoView.init(row.soId);
    },
    // 查询明细按钮操作
    handleGoApprove(row){
      this.$refs.infoView.open = true;
      this.approveFlag=true;
      this.$refs.infoView.init(row.soId);
    },
  }
};
</script>
